package com.woniuxy.mapper;

import com.woniuxy.entity.Comment;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CommentMapper {
    void add(Comment comment);

    void updateOriginIdIfNull(Integer id);

    @Select("select count(*) from comment where user_id= #{userId}")
    Integer count(Integer userId);

    @Select("select origin_id from comment where id= #{pid}")
    Integer findCommentOriginIdById(Integer pid);

    /**
     * 查询某业务下的所有评论 并关联用户信息
     */
    List<Comment> selectCommentsByItemId(Integer itemId);

    /**
     * 根据id查询评论
     */
    @Select("select * from comment where id= #{id}")
    Comment findCommentById(Integer id);

    /**
     * 删除评论
     */
    @Delete("delete from comment where id= #{id}")
    void deleteCommentById(Integer id);
}
